/**
 *
 *  Copyright (c) 2011, AstroDAbis
 *  All rights reserved.
 *
 *  Redistribution and use in source and binary forms, with or without modification,
 *  are permitted provided that the following conditions are met:
 *
 *      * Redistributions of source code must retain the above copyright notice,
 *        this list of conditions and the following disclaimer.
 *      * Redistributions in binary form must reproduce the above copyright notice,
 *        this list of conditions and the following disclaimer in the documentation
 *        and/or other materials provided with the distribution.
 *
 *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
 *  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 *  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
 *  IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
 *  INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
 *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 *  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
 *  LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
 *  OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
 *  OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 */
package org.jiscinvolve.astrodabis.galium.ogsadai;

import org.junit.Test;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.runner.RunWith;  

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import uk.org.ogsadai.client.toolkit.example.SQLClient;

public class SQLClientTestCase
    {

    /**
     * Our test service endpoint.
     * 
    public static final String endpoint = "http://beta.virtual.metagrid.co.uk:8080/dai/services/" ;
     */
    public static final String endpoint = "http://astro.metagrid.co.uk:8080/ogsadai/services/" ;

    /**
     * Our debug logger.
     * 
     */
    private static Log log = LogFactory.getLog(SQLClientTestCase.class);

    /**
     * Simple test to replicate the command line query.
     *
     */
    @Test
    public void frog000()
    throws Exception
        {

        String endpoint = "http://fenrir.roe.ac.uk/dai/services/" ;
        String dataset  = "ukidssDR5" ;
        String query    = "Select a.ra, a.dec, a.sourceID From gcsPointSource as a Where a.ra Between '56.0' And '57.9' And a.dec Between '24.0' And '24.2'" ;

        String[] args = {
            "-u", endpoint,
            "-d", dataset,
            "-q", query
            } ;

        SQLClient client = new SQLClient();
        client.execute(
            args
            );

        }

    /**
     * Simple test for direct JDBC connection.
     * Test disabled, as it requires a JDBC connection to local test database. 
     *
     */
    //@Test
    public void frog001()
    throws Exception
        {

        String dataset  = "jdbctest" ;
        String query    = "SELECT * FROM twomass LIMIT 10" ;

        String[] args = {
            "-u", endpoint,
            "-d", dataset,
            "-q", query
            } ;

        SQLClient client = new SQLClient();
        client.execute(
            args
            );

        }

    /**
     * Simple test for remote TAP service at ROE. 
     *
     */
    @Test
    public void frog002()
    throws Exception
        {

        String dataset  = "ROEukidssDR5" ;
        String query    = "Select a.sourceID, a.ra, a.dec From gcsSource as a Where a.ra Between '56.28' And '56.30' And a.dec Between '50.60' And '50.62'";

        String[] args = {
            "-u", endpoint,
            "-d", dataset,
            "-q", query
            } ;

        SQLClient client = new SQLClient();
        client.execute(
            args
            );

        }


    /**
     * Simple test for remote TAP service at ROE. 
     *
     */
    @Test
    public void frog003()
    throws Exception
        {

        String dataset  = "ROEsdssDR7" ;
        String query    = "Select a.objID, a.ra, a.dec From PhotoObj as a Where a.ra Between '56.28' And '56.30' And a.dec Between '50.60' And '50.62'";

        String[] args = {
            "-u", endpoint,
            "-d", dataset,
            "-q", query
            } ;

        SQLClient client = new SQLClient();
        client.execute(
            args
            );

        }
    }
